
Page({
  data: {
    x: 0,
    y: 0,
    hidden: true,
    defaultMotor:'../../images/motoroff.png',
    extraClasses: ''
    
  },
  customData:{
    state:false

  },
  triggerTransition: function () {
    if (this.data.extraClasses == 'box-transition box-moved') {
      this.setData({
        extraClasses: 'box-transition'
      })
    } else {
      this.setData({
        extraClasses: 'box-transition box-moved'
      })
    }
  },
  triggerAnimation: function () {
    this.setData({
      extraClasses: 'box-animation'
    })
    
  },
  transitionEnd: function () {
    console.log('渐变已结束')
    this.setData({
      extraClasses: ''
    })
  },
  animationStart: function () {
    console.log('动画已开始')
  },
  animationIteration: function () {
    console.log('动画进行中')
  },
  start (e) {
    this.setData({
      hidden: false,
      x: e.touches[0].x,
      y: e.touches[0].y
    })
  },
  move (e) {
    this.setData({
      x: e.touches[0].x,
      y: e.touches[0].y
    })
    console.log("x-->"+e.touches[0].x)
    console.log("y-->"+e.touches[0].y)
  },
  end (e) {
    this.setData({
      hidden: true
    })
  },

  onLoad: function(){
    const ctx = wx.createCanvasContext('myCanvas')
    ctx.drawImage('../../images/logo.png', -30, -10, 380, 250)
    ctx.draw()
  },
  
  setMotor:function(){
    var  status = this.customData.state
    console.log(status)
    var motorOn = '../../images/motoron.png'
    var motorOff = '../../images/motoroff.png'
    if (!status) {
      this.setData({
        defaultMotor:motorOn,
      })
    }else{
      this.setData({
        defaultMotor:motorOff,
      })
    }
    this.customData.state = !status
  },
  sendBullet:function(){
    var  status = this.customData.state
    if (status) {
      this.triggerTransition()
    wx.vibrateShort()
    } else {
      wx.showToast({
        title: '请开启飞轮',
        icon: 'none'
      })
    }
    
    
    
  },


})